package cn.udrm.water.base.v1.manager.restful;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.udrm.water.base.v1.commons.models.ResponseParam;
import cn.udrm.water.base.v1.commons.models.ZTreeNodeVo;
import cn.udrm.water.base.v1.manager.dto.BaseOrganizationDto;
import cn.udrm.water.base.v1.manager.service.BaseOrganizationService;

@RestController
@RequestMapping(value="v1/restful/organization")
public class BaseOrganizationRestful {
	@Autowired
	private BaseOrganizationService organizationService;
	
	@PostMapping(value="save")
	public ResponseParam<BaseOrganizationDto> save(@RequestBody BaseOrganizationDto organizationDto) {
		BaseOrganizationDto save = organizationService.save(organizationDto);
		return new ResponseParam<BaseOrganizationDto>("数据保存成功", 200, save);
	}
	
	@PostMapping(value="update")
	public ResponseParam<BaseOrganizationDto> update(@RequestBody BaseOrganizationDto organizationDto) {
		BaseOrganizationDto save = organizationService.update(organizationDto);
		return new ResponseParam<BaseOrganizationDto>("数据更新成功", 200, save);
	}
	
	/**
	 * 获取组织机构树（只获取角色）
	 * @return
	 */
	@GetMapping(value="getOrgZtreeOnlyRoles")
	public ResponseParam<List<ZTreeNodeVo>> getOrgZtreeOnlyRoles() {
		List<ZTreeNodeVo> orgZtree = organizationService.getOrgZtreeOnlyRoles();
		return new ResponseParam<List<ZTreeNodeVo>>("数据获取成功", 200, orgZtree);
	}
	/**
	 * 获取组织机构树
	 * @return
	 */
	@GetMapping(value="getOrgZtree")
	public ResponseParam<List<ZTreeNodeVo>> getOrgZtree() {
		List<ZTreeNodeVo> orgZtree = organizationService.getOrgZtree();
		return new ResponseParam<List<ZTreeNodeVo>>("数据获取成功", 200, orgZtree);
	}
	
	@GetMapping(value="getSelfById/{id}")
	public ResponseParam<BaseOrganizationDto> getSelfById(@PathVariable(value="id") String id) {
		BaseOrganizationDto selfById = organizationService.getSelfById(id);
		return new ResponseParam<BaseOrganizationDto>("数据获取成功", 200, selfById);
	}

}
